package com.neudu.glsb.mapper;

import com.neudu.glsb.pojo.EmployeeLeave;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface EmployeeLeaveMapper extends BaseMapper<EmployeeLeave> {
    // 根据 ID 查询请假申请详情并获取员工姓名
    @Select("SELECT el.id, el.employee_id, el.start_date, el.end_date, el.reason, el.status, e.employee_name " +
            "FROM employee_leave el " +
            "LEFT JOIN employees e ON el.employee_id = e.id " +
            "WHERE el.id = #{id}")
    EmployeeLeave selectEmployeeLeaveByIdWithEmployeeName(Integer id);
    // 根据审批状态和员工姓名进行查询
    List<EmployeeLeave> selectLeavesByStatusAndEmployeeName(String status, String employeeName);// 根据员工姓名模糊查询请假申请
    @Select("SELECT el.id, el.employee_id, el.start_date, el.end_date, el.reason, el.status, e.employee_name " +
            "FROM employee_leave el " +
            "LEFT JOIN employees e ON el.employee_id = e.id " +
            "WHERE e.employee_name LIKE CONCAT('%', #{employeeName}, '%')")
    List<EmployeeLeave> searchByName(@Param("employeeName") String employeeName);
}